package com.lehecai.core.api.event;

import com.lehecai.core.IntegerBeanLabel;
import com.lehecai.core.IntegerBeanLabelItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhangzq on 14-11-14.
 */
public class UserPicType extends IntegerBeanLabelItem {

    private static final Logger logger = LoggerFactory.getLogger(PropType.class.getName());

    private static List<UserPicType> items = new ArrayList<UserPicType>();
    private static List<UserPicType> queryItems = new ArrayList<UserPicType>();

    protected UserPicType(String name, int value, boolean queryOnly) {
        super(UserPicType.class.getName(), name, value);
        queryItems.add(this);
        if (!queryOnly) {
            items.add(this);
        }
    }

    protected UserPicType(String name, int value) {
        this(name, value, false);
    }

    public static UserPicType getItem(int value){
        try {
            return (UserPicType) UserPicType.getResult(UserPicType.class.getName(), value);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }

    public static UserPicType getItemByName(String name){
        try {
            Map<String, IntegerBeanLabel> nameMaps = null;
            Map<Integer, IntegerBeanLabel> valueMaps = null;
            if (!nameMap.containsKey(UserPicType.class.getName())) {
                nameMaps = new HashMap<String, IntegerBeanLabel>();
                valueMaps = new HashMap<Integer, IntegerBeanLabel>();
                nameMap.put(UserPicType.class.getName(), nameMaps);
                valueMap.put(UserPicType.class.getName(), valueMaps);
            }
            return (UserPicType) UserPicType.get(UserPicType.class.getName(), name);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }

    public static List<UserPicType> getItems() {
        return items;
    }

    public static List<UserPicType> getQueryItems() {
        return queryItems;
    }
    public static final UserPicType ALL = new UserPicType("全部", -1, true);
    public static final UserPicType BOY_ODD = new UserPicType("boy-odd", 1);
    public static final UserPicType BOY_EVEN = new UserPicType("boy-even", 2);
    public static final UserPicType GIRL_ODD = new UserPicType("girl-odd", 3);
    public static final UserPicType GIRL_EVEN = new UserPicType("girl-even", 4);
}
